梦入琼楼寒有月,行过石树冻无烟

Dcat Admin 工具栏按钮

Dcat Admin 在 DcatAdmin 数据表格之上为我们提供了工具栏按钮,使得我们可以在数据表格页面中自定义按下后的弹窗页面,通过 app/Admin/Actions/Tool 目录中定义菜单栏工具为 MovieShowTool.php ,并继承自 AbstractTool(Dcat\Admin\Grid\Tools\AbstractTool)

1
除了可以使用之前在数据表格中所使用到的页面脚手架之外,我们还可以使用 Artisan Cli 进行构建,数据表格、数据表单、数据详情和模型树,参考官方文档进行使用 [基本使用 | 动作 |《Dcat Admin 中文文档 2.x》| Laravel China 社区 (learnku.com)](https://learnku.com/docs/dcat-admin/2.x/basic-use/8124)

对于 Artisan Cli Command,我们可以通过 php artisan admin:action 来选择 show-tool 即 Dcat Admin 工具栏按钮自定义,然后输入类名称目录即可:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
>php artisan admin:action

Which type of action would you like to make?:
[0] default
[1] grid-batch
[2] grid-row
[3] grid-tool
[4] form-tool
[5] show-tool
[6] tree-row
[7] tree-tool
> 5

Please enter a name of action class:
> MovieOutherTools

Please enter the namespace of action class [App\Admin\Actions\Show]:
> App\Admin\Actions\Tool

App\Admin\Actions\Tool\MovieOutherTools created successfully.

1
数据表单是通过按钮、或者菜单进行调用的。

之后,我们通过工具表单的 Artisan Cli Commad php artisan admin:form MovieOutherForm 命令来生成一个名为 MovieOutherForm 类作为工具表单,在 app/Admin/Forms 目录内:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php  

namespace App\Admin\Forms;

use Dcat\Admin\Widgets\Form;

class MovieOutherForm extends Form
{
/**
* 处理表单提交请求 * * @param array $input
*
* @return mixed
*/
public function handle(array $input)
{ // dump($input);

// return $this->response()->error('Your error message.');
return $this
->response()
->success('Processed successfully.')
->refresh();
}

/**
* 构建表单. */
public function form()
{
$this->text('name')->required();
$this->email('email')->rules('email');
}

/**
* 表单的数据. * * @return array
*/
public function default()
{ return [
'name' => 'John Doe',
'email' => 'John.Doe@gmail.com',
];
}
}

此时 MovieOutherForm 就会集成 Form,即 Dcat\Admin\Widgets\Form 使得可以用来构建表单和提交数据,以及全方位的独立处理数据,且不需要注册额外路由。

1
2
3
通过 ```php artisan list``` 可以列出所有的 Laravel Artisan 命令,之后我们输入 ```php artisan list admin``` 来查看 Dcat Admin 的所有命令和语法。

此外,我们还可以通过使用 ```php artisan help make:console``` 来查看 Artisan make Console 的具体用法。

在此之前,我们通过 Admin | 代码生成器 网页脚手架所自动生成的控制器、模型以及数据仓库外,还可以通过 Illuminate\Database\Eloquent\Model | Laravel API 使得 app\Models\Shop 实现抽象模型,然后通过 Service 以此来中转数据。

⬅️ Go back